﻿using System;
using AvalonDock;
using Foundation;
using Poet.Properties;

namespace Poet.Modules
{
    internal class ViewModeManager
    {
        public static bool LoadCurrent(DockingManager dockingManager)
        {
            var path = PathProvider.FindFileByName(Settings.Default.AvalonDockLayout);
            return PathProvider.Exists(path) && LoadDockLayout(dockingManager, path);
        }

        public static bool SaveCurrent(DockingManager dockingManager)
        {
            var path = PathProvider.FindFileByName(Settings.Default.AvalonDockLayout);
            return SaveDockLayout(dockingManager, path);
        }

        public static bool LoadDockLayout(DockingManager dockingManager, string fileName)
        {
            try
            {
                dockingManager.RestoreLayout(fileName);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool SaveDockLayout(DockingManager dockingManager, string fileName)
        {
            try
            {
                dockingManager.SaveLayout(fileName);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
